﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="computerwinkel">
    <html>
      <head>
        <title>WinkelTransform</title>
      </head>
      <body>
        <h1>
          <img src="logo.jpg"/>Winkel rijen / vakken gegevens.
        </h1>
        <br/>
        <table>
          <xsl:apply-templates select="rijen/rij">
            <xsl:sort select="rijen/rij/@rij_id"/>
          </xsl:apply-templates>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="rij">
    <tr>
      <td><font color="Gray">RijID:</font><xsl:value-of select="@rij_id"/></td>
    </tr>
    <tr>
      <td>
        <font color="Gray">Rijnummer:</font><xsl:value-of select="rij_nummer"/>
      </td>
    </tr>
    <tr>
      <td></td>
      <td>
        <font color="Gray">Vakken :</font><br/> 
      </td>
    </tr>
        <xsl:apply-templates select="vakken"/>
    
  </xsl:template>

  
  <xsl:template match="vakken">
    
    <xsl:variable name="v_rij_id">
      <xsl:value-of select="@rij_id"/>
    </xsl:variable>
    
    <xsl:apply-templates select="vak">
        <xsl:sort select="@vak_nummer" data-type="number"/>
        <!-- 123 en 45 zijn strings dus op volgorde : eerst 123 en dan 45 oplossing : data-type aangeven !   -->
      </xsl:apply-templates>

  </xsl:template>

  <xsl:template match="vak">
    
    <xsl:variable name="v_artikel_id">
      <xsl:value-of select="@artikel_id"/>
    </xsl:variable>
    <tr><td></td><td>Vaknummer: <xsl:value-of select="vak_nummer"/></td></tr>
    <tr><td></td><td>Aantal artikelen: <xsl:value-of select="aantal"/></td></tr>

    <xsl:apply-templates select="/computerwinkel/artikelen/artikel[@artikel_id=$v_artikel_id]"/>
    
  </xsl:template>

  <xsl:template match="artikel">
    <tr>
      <td></td>
      <td></td>
      <td>
        <font color="Gray">Artikel:</font>
      </td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td><xsl:value-of select="artikel_naam"/></td></tr>
    <tr>
      <td></td>
      <td></td>
      <!--<td></td><td><xsl:value-of select="prijs"/></td></tr> -->
      <xsl:call-template name="formatPrice">
        <xsl:with-param name="prijs" select="prijs"/>
      </xsl:call-template>
    </tr>
    <tr>
      <td></td>
      <td></td><td><xsl:value-of select="merk"/></td></tr>
    <tr>
      <td></td>
      <td></td><td><xsl:value-of select="type"/></td></tr>
  </xsl:template>

  <xsl:template name="formatPrice">
    <xsl:param name="prijs">0</xsl:param>
    <xsl:value-of select="format-number(prijs,'€#,##0.00')"/>
  </xsl:template>
  
</xsl:stylesheet>
